//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateCertification {
        private readonly ICertificationRepository _certificationRepository;

        public CreateCertification(ICertificationRepository certificationRepository) {
            _certificationRepository = certificationRepository;
        }

        public void Execute(Guid userId, ICreateCertificationCommand certificationForm) {
            if (certificationForm == null)
                throw new ArgumentNullException("certificationForm");

            try {
                var certification = certificationForm.ConvertToEntity();
                _certificationRepository.Create(certification);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
